// pages/daily-recommendation/daily-recommendation.js
const _this = this
Page({

  /**
   * 页面的初始数据
   */
  data: {
    head: "http://192.168.0.26:8081/img/tea.jpg",
    ids: 1,
    songsheetCode: "",
    show: true,
    list: [{
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版sadsadsaddddddddddddddd)",
      "type": "独家"
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
      "type": "SQ"
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }, {
      "img": "../../resource/images/song-list-1.jpg",
      "name": "尘埃",
      "singer": "王雨桐",
      "album": "尘埃(完整版)",
    }]
  },
  collect() {
    if (wx.getStorageSync('token') == 1) {
      wx.request({
        url: 'http://192.168.0.26:8081/userCollect/updateUserCollect',
        method: "POST",
        data: {
          userCode: wx.getStorageSync('userCode'),
          songsheetCode: this.data.songsheetCode
        },
        success: (res) => {
          console.log(res.data.data);
          this.setData({
            show: !this.data.show
          })
        }

      })
      // this.setData({
      //   animationsss: this.animation.export(),
      //   masklayerboolsss: false,
      // })
      // this.onLoad()
    } else {
      wx.showModal({
        title: '用户未登录',
        cancelColor: 'cancelColor',
      })
    }

  },

  SinglePlay(){
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.songsheetCode);
    console.log(options.id);
    let _id = wx.getStorageSync('userCode');

    this.setData({
      songsheetCode: options.songsheetCode
    })
    // console.log("id",_id);
    if (wx.getStorageSync('token') == 1) {
      wx.request({
        url: 'http://192.168.0.26:8081/userCollect/getUserCollectByUserCode',
        method: "post",
        data: {
          userCode: _id
        },
        success: (res) => {
          console.log(res.data.data);
          for (let i = 0; i < res.data.data.length; i++) {

            if (res.data.data[i].songsheetCode == options.songsheetCode) {
              // this.data.show= true;
              console.log("已收藏");
              console.log(this.data.show);
              // this.data.show = false;
              this.setData({
                show: false
              })
              console.log(this.data.show);
              break;
            } else {
              console.log(res.data.data[i].songsheetCode);
              console.log(options.songsheetCode);
              console.log(res.data.data[i].songsheetCode, options.songsheetCode, res.data.data[i].songsheetCode == options.songsheetCode);
              // console.log(res.data.data[i].songsheetCode != options.songsheetCode);
              // this.data.show= false;
              this.setData({
                show: true
              })
              console.log("未收藏");
            }
          }
        }

      })
    } else {
      this.setData({
        show: true
      })
    }
    // console.log(options.id);

    wx.request({
      url: 'http://192.168.0.26:8081/songSheet/getSongSheetById',
      method: "get",
      data: {
        id: options.id
      },
      success: (res) => {
        // console.log(res.data.data);
        if (res.data.data.music != "" && res.data.data.music != null) {
          for (let i = 0; i < res.data.data.music.length; i++) {
            res.data.data.music[i].imgUrl =
              "http://192.168.0.26:8081" + res.data.data.music[i].imgUrl;
          }
        }
        this.setData({
          list: res.data.data
        })
        // console.log(this.data.list);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})